<body>

<style>
	.report_table {border-collapse:collapse}
	.report_table td{padding:2px 6px}
	.report_table thead{background:#eee}
	.report_table th{padding:4px}	
</style>

<h2><?=$this->report['title']?></h2>

<?
	if ($this->args['mode'] == 'print')
	{
		$mvc->theme->name = 'default';

		if ($this->report['workers'])
		{
			foreach($this->report['workers'] as $worker)
			{
				if ($this->args['worker'] == $worker['id']) print($worker['fio']);
			}
		}
	}
	else
	{
?>

<form method="post">
	<?
		if ($this->report['workers'])
		{
			echo '<select name="worker">';
			echo '<option value="0" '.($this->args['worker'] ? 'selected' : '').'>(Все сотрудники)</option>';
			foreach($this->report['workers'] as $worker)
			{
				$selected = ($this->args['worker'] == $worker['id']) ? 'selected' : '';
				echo '<option value="'.$worker['id'].'" '.$selected.'>'.$worker['fio'].'</option>';
			}
			echo '</select>';
		}
	?>

	<?
		if ($this->report['cars'])
		{
			echo '<select name="car">';
			echo '<option value="0" '.($this->args['car'] ? 'selected' : '').'>(Все машины)</option>';
			foreach($this->report['cars'] as $car)
			{
				$selected = ($this->args['car'] == $car['id']) ? 'selected' : '';
				echo '<option value="'.$car['id'].'" '.$selected.'>'.$car['name'].'</option>';
			}
			echo '</select>';
		}
	?>

	<input type="hidden" name="mode" value="none">
	с <input type="text" name="date1" class="datepicker" value="<?=$_REQUEST['date1']?>">
	по <input type="text" name="date2" class="datepicker" value="<?=$_REQUEST['date2']?>">
	<input type="submit" value="Обновить">
	<input type="submit" onClick="this.form.elements['mode'].value = 'print'" value="Печать">
	
</form>
<? } ?>

<table border="1" class="report_table">
	<thead>
		<tr>
			<?
				// Заголовок таблицы берем из $this->report['titles'].
				foreach($this->report['titles'] as $title)
				{
					echo '<th>'.$title.'</th>';
				}
			?>		
		</tr>
	</thead>
	<?
		foreach($this->report['data'] as $row)
		{
			echo '<tr>';
			// Если поля таблицы($this->report['fields']) определениы, то берем данные по ним.
			if ($this->report['fields'])
			{
				foreach($this->report['fields'] as $fname)
				{					
					echo '<td>'.$row[$fname].'</td>';
				}
			}
			else // Иначе просто выводим все поля $this->report['data']
			{
				foreach($row as $value)
				{
					echo '<td>'.$value.'</td>';
				}
			}
			echo '</tr>';
		}
	?>
</table>

<?
	if ($this->args['mode'] != 'print')
		echo '<a href="<?=$this->base_url?>">Назад</a>';
	else
		echo '<script> window.print(); </script>';

?>

</body>
</html>